package me.zhengjie.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.config.RsaProperties;
import me.zhengjie.domain.vo.PhoneVo;
import me.zhengjie.service.AliSendSmsService;
import me.zhengjie.utils.RsaUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/smsCode")
@Api(tags = "工具：手机验证码管理")
public class AliSendSmsController {

    private final AliSendSmsService aliSendSmsService;

    public AliSendSmsController(AliSendSmsService aliSendSmsService) {
        this.aliSendSmsService = aliSendSmsService;
    }

    @Log("发送手机验证码")
    @PostMapping
    @ApiOperation("发送手机验证码")
    @AnonymousAccess
    public ResponseEntity<Object> sendPhoneCode(@RequestBody PhoneVo phoneVo) throws Exception {
        String realPhone = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, phoneVo.getPhone());

        return new ResponseEntity<>(aliSendSmsService.send(realPhone), HttpStatus.OK);
    }
}
